package cn.schoolwow.util.test.module.query.instanceList.flow.query;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.query.instanceList.QueryInstanceList;
import cn.schoolwow.util.test.module.common.domain.User;
import org.junit.Assert;

import java.util.List;

public class InstanceQuerySingleFieldFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        List<User> userList = (List<User>) flowContext.checkData("userList");

        List<String> usernameList = QueryInstanceList.newQuery(userList)
                .execute()
                .getSingleFieldValueList("username");
        Assert.assertEquals(userList.size(), usernameList.size());
        for(String username:usernameList){
            User expectUser = QueryInstanceList.newQuery(userList)
                    .addQuery("username", username)
                    .execute()
                    .checkOne();
            Assert.assertNotNull(expectUser);
        }
    }

    @Override
    public String name() {
        return "用户实例列表单个字段查询";
    }
}
